package com.lkd.handler;


import com.lkd.business.MsgHandler;
import com.lkd.common.VMSystem;
import com.lkd.config.TopicConfig;
import com.lkd.contract.OrderCheck;
import com.lkd.emq.Topic;
import com.lkd.entity.OrderEntity;
import com.lkd.service.OrderService;
import com.lkd.utils.JsonUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
@Topic(TopicConfig.ORDER_CHECK_TOPIC)
@Slf4j
public class OrderCheckHandler implements MsgHandler {

    @Autowired
    OrderService orderService;


    @Override
    public void process(String jsonMsg) throws IOException {
        //解析消息
        log.info("接受到消息");
        OrderCheck orderCheck = JsonUtil.getByJson(jsonMsg, OrderCheck.class);
        //查询订单，如果未支付，则修改为无效订单
        OrderEntity orderEntity = orderService.getByOrderNo(orderCheck.getOrderNo());
        if (orderEntity.getStatus()== VMSystem.PAY_STATUS_NOPAY){
            //未支付,修改状态为无效
            orderEntity.setStatus(VMSystem.ORDER_STATUS_INVALID);
            orderService.updateById(orderEntity);//更新状态为无效
        }


    }
}
